/* Copyright (c) 2006 YourNameHere
   See the file LICENSE.txt for licensing information. */

function startFind() {
    var prefsvc = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch2);
    var userWantsPrefill = true;
    this.open(aMode);

    if (this._flashFindBar) {
        this._flashFindBarTimeout = setInterval(function(aSelf) {
            aSelf._flash();
        },
        500, this);
        prefsvc.setIntPref("accessibility.typeaheadfind.flashBar", --this._flashFindBar);
    }

    if (this.prefillWithSelection) userWantsPrefill = prefsvc.getBoolPref("accessibility.typeaheadfind.prefillwithselection");

    var initialString = (this.prefillWithSelection && userWantsPrefill) ? this._getInitialSelection() : null;
    if (initialString) {
        this._findField.value = initialString;
        this._enableFindButtons(true);
    } else if (!this._findField.value) this._enableFindButtons(false);

    this._findField.select();
    this._findField.focus();

}

function find() {
    var val = aValue || this._findField.value

    this._enableFindButtons(val);
    if (this.getElement("highlight").checked) this._setHighlightTimeout();

    this._updateCaseSensitivity(val);

    var fastFind = this.browser.fastFind;
    var res = fastFind.find(val, this._findMode == this.FIND_LINKS);
    this._updateFoundLink(res);
    this._updateStatusUI(res, false);

    if (this._findMode != this.FIND_NORMAL) this._setFindCloseTimeout();

    return res;

}